{% extends "base.html" %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
    <h2>在职员工列表</h2>
    <a href="{{ url_for('employee.add_employee') }}" class="btn btn-primary">添加员工</a>
</div>

<div class="card">
    <div class="card-body">
        <form method="GET" action="{{ url_for('employee.search_employees') }}" class="mb-4">
            <div class="input-group">
                <input type="text" name="term" class="form-control" placeholder="搜索员工..." value="{{ search_term }}">
                <button type="submit" class="btn btn-outline-secondary">搜索</button>
            </div>
        </form>

        <div class="table-responsive">
            <table class="table table-striped">
                <thead>
                    <tr>
                        <th>姓名</th>
                        <th>身份证号</th>
                        <th>手机号</th>
                        <th>部门</th>
                        <th>职位</th>
                        <th>入职日期</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for employee in employees %}
                    <tr>
                        <td>{{ employee.name }}</td>
                        <td>{{ employee.id_card }}</td>
                        <td>{{ employee.phone }}</td>
                        <td>{{ employee.department }}</td>
                        <td>{{ employee.position }}</td>
                        <td>{{ employee.hire_date }}</td>
                        <td>
                            <div class="btn-group">
                                <a href="{{ url_for('employee.employee_detail', id=employee.id) }}" class="btn btn-sm btn-info">查看</a>
                                <a href="{{ url_for('employee.edit_employee', id=employee.id) }}" class="btn btn-sm btn-warning">编辑</a>
                                <button type="button" class="btn btn-sm btn-danger" data-bs-toggle="modal" data-bs-target="#deleteModal{{ employee.id }}">
                                    删除
                                </button>
                            </div>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>

{% for employee in employees %}
<!-- 删除确认模态框 -->
<div class="modal fade" id="deleteModal{{ employee.id }}" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">确认删除</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body">
                确定要删除员工 {{ employee.name }} 吗？此操作不可恢复。
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                <a href="{{ url_for('employee.delete_employee', id=employee.id) }}" class="btn btn-danger">确认删除</a>
            </div>
        </div>
    </div>
</div>
{% endfor %}
{% endblock %} 